<!DOCTYPE html>
<html>
<head>
	<title>waves</title>
	<script type="text/javascript" src="./js/wave.js"></script>
</head>
<body>

<canvas id="myCanvas"></canvas>


<script type="text/javascript">
	
	var waveWidth = 300,
    offset = 0,
    waveHeight = 8,
    waveCount = 5,
    startX = -100,
    startY = 208,
    progress = 0,
    progressStep = 1,
    d2 = waveWidth / waveCount,
    d = d2 / 2,
    hd = d / 2,
    c = document.getElementById("myCanvas"),
    ctx = c.getContext("2d");
 
	function tick() {
	    offset -= 5;
	    progress += progressStep;
	    if (progress > 220 || progress < 0) progressStep *= -1;
	 
	    if (-1 * offset === d2) offset = 0;
	    ctx.clearRect(0, 0, c.width, c.height);
	    ctx.beginPath();
	    var offsetY = startY - progress;
	    ctx.moveTo(startX - offset, offsetY);
	 
	    for (var i = 0; i < waveCount; i++) {
	        var dx = i * d2;
	        var offsetX = dx + startX - offset;
	        ctx.quadraticCurveTo(offsetX + hd, offsetY + waveHeight, offsetX + d, offsetY);
	        ctx.quadraticCurveTo(offsetX + hd + d, offsetY - waveHeight, offsetX + d2, offsetY);
	    }
	    ctx.lineTo(startX + waveWidth, 300);
	    ctx.lineTo(startX, 300);
	    ctx.fill();
	 
	    requestAnimationFrame(tick);
	}
 
	tick();

</script>

</body>
</html>